
/***************************************************************************************************************************************
		
		Replication code for:

		Pedro Accorsi and Ron Krebs, "The Soldier in the State: Explaining Public Trust in the Military" 
		Comparative Political Studies
		
****************************************************************************************************************************************

		Table of Contents:
		
		1 - Main analysis
		2 - Appendix
	
***************************************************************************************************************************************/ 

clear
use "SoldierInState.dta"

/***************************************************************************************************************************************

	1 - MAIN ANALYSIS 

***************************************************************************************************************************************/

// Figure 1

// Preserve original data
preserve 

// Collapse to get means by region and year
collapse (mean) trust_military, by(region year)

// Generate plots for each region
forvalues i = 1/6 {
    twoway (line trust_military year if region == `i') ///
        , title("`label`i''", size(large)) ///
        xtitle("Year", size(medium)) ///
        ylabel(, angle(horizontal) labsize(medium)) ///
        ytitle("Trust in Military", size(medium)) ///
        name(region`i', replace) ///
        scheme(s1mono)
}

// Combine all plots
graph combine region1 region2 region3 region4 region5 region6, ///
    rows(2) ///
    ycommon ///
    xsize(12) ysize(6) ///
	scheme(s1mono)

// Restore original data
restore

***************************************************************************************************************************************/

// Figure 2

// Create the overall sample graph
graph bar trust_military trust_police trust_financial_inst gov_conf trust_judiciary, ///
    title("World", size(large)) ///
    ytitle("Trust Level", size(medium)) ///
    ylabel(, labsize(medium) angle(horizontal)) ///
    scheme(s1mono) ///
    bar(1, fcolor("black") lcolor("navy")) ///
    bar(2, fcolor("navy") lcolor("navy")) ///
    bar(3, fcolor("maroon") lcolor("maroon")) ///
    bar(4, fcolor("forest_green") lcolor("forest_green")) ///
    bar(5, fcolor("gold") lcolor("gold")) ///
    legend(label(1 "Military") label(2 "Police") ///
           label(3 "Financial Institutions") label(4 "Government") label(5 "Judiciary") ///
           size(medium) rows(2) position(6)) ///
    name(overall, replace)

// Create label local before the loop
forvalues i = 1/6 {
    local label`i' : label (region) `i'
}

// Generate plots for each region
forvalues i = 1/6 {
    graph bar trust_military trust_police trust_financial_inst gov_conf trust_judiciary ///
        if region == `i', ///
        title("`label`i''", size(large)) ///
        ytitle("Trust Level", size(medium)) ///
        ylabel(, labsize(medium) angle(horizontal)) ///
        scheme(s1mono) ///
    bar(1, fcolor("black") lcolor("navy")) ///
    bar(2, fcolor("navy") lcolor("navy")) ///
    bar(3, fcolor("maroon") lcolor("maroon")) ///
    bar(4, fcolor("forest_green") lcolor("forest_green")) ///
    bar(5, fcolor("gold") lcolor("gold")) ///
    legend(off) ///
        name(region`i', replace)
}



// Combine graphs
graph combine region1 region2 region3 region4 region5 region6, ///
	rows(2) ///
    ycommon ///
    xsize(16) ysize(10) ///
	scheme(s1mono) ///
    name(regions, replace)
graph combine overall regions, ///
	rows(1) ///
    ycommon ///
    xsize(16) ysize(10) ///
	scheme(s1mono) ///
    name(all, replace)

***************************************************************************************************************************************/

// Figure 3

xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust
coefplot, keep(trust_police_z trust_judiciary_z gov_corrupt_z military_dim_z_mavg2 civwar conscript) ///
    order(trust_police_z trust_judiciary_z gov_corrupt_z military_dim_z_mavg2 civwar conscript) ///
    coeflabels(trust_police_z = "Trust Police" ///
              trust_judiciary_z = "Trust Judicial System" ///
              gov_corrupt_z = "Government Corruption Perception" ///
              military_dim_z_mavg2 = "Military Dimension Index" ///
              civwar = "Civil War" ///
              conscript = "Conscription") ///
    xline(0, lcolor(gray) lpattern(solid)) ///
    msymbol(circle) mcolor(black) ciopts(recast(rcap) lcolor(black)) ///
    xlabel(, labsize(medium)) ///
    ylabel(, labsize(medium)) ///
    scheme(s1mono) ///
    ysize(3) xsize(5)

***************************************************************************************************************************************/

// Figure 4

// First plot (living standards)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z conscript civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln personnel_pc_ln c.military_dim_mavg2##c.living_std_improve i.year, corr(ar1) link(probit) family(binomial) robust
sum living_std_improve if e(sample), d
margins, at(living_std_improve=(0.21 0.62) military_dim_mavg2=(0 0.5 1)) ///
    atmeans vsquish ///
    post
marginsplot, name(living_standards, replace) ///
    plot1opts(connect(line) msymbol(circle) lcolor(navy) mcolor(navy) lpattern(solid)) ///
    plot2opts(connect(line) msymbol(circle_hollow) lcolor(maroon) mcolor(maroon) lpattern(dash)) ///
    plot3opts(connect(line) msymbol(diamond) lcolor(forest_green) mcolor(forest_green) lpattern(shortdash)) ///
    ci1opts(lcolor(navy)) ///
    ci2opts(lcolor(maroon)) ///
    ci3opts(lcolor(forest_green)) ///
    xlabel(.21 "10th" .62 "90th", labsize(medium)) ///
    ylabel(, format(%9.2f) labsize(medium) angle(horizontal)) ///
    title("(a) Living Standards", size(large)) ///
    xtitle("Percentiles", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(label(1 "MDI = 0") label(2 "MDI = 0.5") label(3 "MDI = 1") rows(1) size(medium)) ///
    scheme(s1mono)

// Second plot (GDP growth)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln life_expectancy trust_police_z trust_judiciary_z conscript civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln personnel_pc_ln c.military_dim_mavg2##c.gdp_growth i.year, corr(ar1) link(probit) family(binomial) robust
sum gdp_growth if e(sample), d
margins, at(gdp_growth=(-.133 .823) military_dim_mavg2=(0 0.5 1)) ///
    atmeans vsquish ///
    post
marginsplot, name(gdp_growth, replace) ///
    plot1opts(connect(line) msymbol(circle) lcolor(navy) mcolor(navy) lpattern(solid)) ///
    plot2opts(connect(line) msymbol(circle_hollow) lcolor(maroon) mcolor(maroon) lpattern(dash)) ///
    plot3opts(connect(line) msymbol(diamond) lcolor(forest_green) mcolor(forest_green) lpattern(shortdash)) ///
    ci1opts(lcolor(navy)) ///
    ci2opts(lcolor(maroon)) ///
    ci3opts(lcolor(forest_green)) ///
    xlabel(-.133 "10th" .823 "90th", labsize(medium)) ///
    ylabel(, format(%9.2f) labsize(medium) angle(horizontal)) ///
    title("(b) GDP Growth", size(large)) ///
    xtitle("Percentiles", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(label(1 "MDI = 0") label(2 "MDI = 0.5") label(3 "MDI = 1") rows(1) size(medium)) ///
    scheme(s1mono)

// Combine graphs
graph combine living_standards gdp_growth, ///
    rows(1) ///
    ycommon ///
    scheme(s1color) ///
    xsize(12) ysize(7)

***************************************************************************************************************************************/

// Figure 5

xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln personnel_pc_ln c.military_dim_mavg2##c.hrights i.year, corr(ar1) link(probit) family(binomial) robust
sum hrights if e(sample), d
margins, at(hrights=(-1.3 2.7) military_dim_mavg2=(0 0.5 1)) ///
    atmeans vsquish ///
    post
marginsplot, name(hrights_plot, replace) ///
    plot1opts(connect(line) msymbol(circle) lcolor(navy) mcolor(navy) lpattern(solid)) ///
    plot2opts(connect(line) msymbol(circle_hollow) lcolor(maroon) mcolor(maroon) lpattern(dash)) ///
    plot3opts(connect(line) msymbol(diamond) lcolor(forest_green) mcolor(forest_green) lpattern(shortdash)) ///
    ci1opts(lcolor(navy)) ///
    ci2opts(lcolor(maroon)) ///
    ci3opts(lcolor(forest_green)) ///
    xlabel(-1.3 "10th" 2.7 "90th", labsize(medium)) ///
    ylabel(, format(%9.2f) labsize(medium) angle(horizontal)) ///
    title("") ///
    xtitle("Human Rights (Percentiles)", size(medium)) ///
    ytitle("") ///
    legend(label(1 "MDI = 0") label(2 "MDI = 0.5") label(3 "MDI = 1") rows(1) size(medium)) ///
    scheme(s1mono) ///
	xsize(7) ysize(5)
	
***************************************************************************************************************************************/

// Figure 6

// First plot (government corruption perception)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z conscript civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln personnel_pc_ln c.military_dim_mavg2##c.gov_corrupt_z i.year, corr(ar1) link(probit) family(binomial) robust
sum gov_corrupt_z if e(sample), d
margins, at(gov_corrupt_z=(-1.270558 1.082455) military_dim_mavg2=(0 0.5 1)) ///
    atmeans vsquish ///
    post
marginsplot, name(corruption, replace) ///
    plot1opts(connect(line) msymbol(circle) lcolor(navy) mcolor(navy) lpattern(solid)) ///
    plot2opts(connect(line) msymbol(circle_hollow) lcolor(maroon) mcolor(maroon) lpattern(dash)) ///
    plot3opts(connect(line) msymbol(diamond) lcolor(forest_green) mcolor(forest_green) lpattern(shortdash)) ///
    ci1opts(lcolor(navy)) ///
    ci2opts(lcolor(maroon)) ///
    ci3opts(lcolor(forest_green)) ///
    xlabel(-1.270558 "10th" 1.082455 "90th", labsize(medium)) ///
    ylabel(, labsize(medsmall) angle(horizontal)) ///
    title("(a) Government Corruption Perception", size(medium)) ///
    xtitle("Percentiles", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(label(4 "MDI = 0") label(5 "MDI = 0.5") label(6 "MDI = 1") rows(1) size(medium)) ///
    scheme(s1mono)

// Second plot (confidence in national government)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z conscript civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln personnel_pc_ln c.military_dim_mavg2##c.gov_conf i.year, corr(ar1) link(probit) family(binomial) robust    
sum gov_conf if e(sample), d
margins, at(gov_conf=(.24 .72) military_dim_mavg2=(0 0.5 1)) ///
    atmeans vsquish ///
    post  
marginsplot, name(confidence, replace) ///
    plot1opts(connect(line) msymbol(circle) lcolor(navy) mcolor(navy) lpattern(solid)) ///
    plot2opts(connect(line) msymbol(circle_hollow) lcolor(maroon) mcolor(maroon) lpattern(dash)) ///
    plot3opts(connect(line) msymbol(diamond) lcolor(forest_green) mcolor(forest_green) lpattern(shortdash)) ///
    ci1opts(lcolor(navy)) ///
    ci2opts(lcolor(maroon)) ///
    ci3opts(lcolor(forest_green)) ///
    xlabel(.24 "10th" .72 "90th", labsize(medium)) ///
    ylabel(, labsize(medsmall) angle(horizontal)) ///
    title("(b) Confidence in the Government", size(medium)) ///
    xtitle("Percentiles", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(label(4 "MDI = 0") label(5 "MDI = 0.5") label(6 "MDI = 1") rows(1) size(medium)) ///
    scheme(s1mono)
   
// Third plot (leadership approval)    
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z conscript civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln personnel_pc_ln c.military_dim_mavg2##c.lead_approve i.year, corr(ar1) link(probit) family(binomial) robust
sum lead_approve if e(sample), d
margins, at(lead_approve=(0.23 0.71) military_dim_mavg2=(0 0.5 1)) ///
    atmeans vsquish ///
    post
marginsplot, name(leadership, replace) ///
    plot1opts(connect(line) msymbol(circle) lcolor(navy) mcolor(navy) lpattern(solid)) ///
    plot2opts(connect(line) msymbol(circle_hollow) lcolor(maroon) mcolor(maroon) lpattern(dash)) ///
    plot3opts(connect(line) msymbol(diamond) lcolor(forest_green) mcolor(forest_green) lpattern(shortdash)) ///
    ci1opts(lcolor(navy)) ///
    ci2opts(lcolor(maroon)) ///
    ci3opts(lcolor(forest_green)) ///
    xlabel(.23 "10th" .71 "90th", labsize(medium)) ///
    ylabel(, labsize(medsmall) angle(horizontal)) ///
    title("(c) Leadership Approval", size(medium)) ///
    xtitle("Percentiles", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(label(4 "MDI = 0") label(5 "MDI = 0.5") label(6 "MDI = 1") rows(1) size(medium)) ///
    scheme(s1mono)
   
// Combine graphs
graph combine corruption confidence leadership, ///
    rows(1) ///
    ycommon ///
    scheme(s1color) ///
    xsize(14) ysize(10)

***************************************************************************************************************************************/

// Figure 7

xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z military_dim_mavg2 civwar crisis_lag1 crisis_victory crisis_tie spend_soldier_z_ln personnel_pc_ln i.conscript##crisis_current i.year, corr(ar1) link(probit) family(binomial) robust
margins, at(crisis_current=(0 1) conscript=(0 1)) ///
    atmeans vsquish ///
    post
marginsplot, ///
    plot1opts(connect(line) msymbol(circle) lcolor(navy) mcolor(navy) lpattern(solid)) ///
    plot2opts(connect(line) msymbol(circle_hollow) lcolor(maroon) mcolor(maroon) lpattern(dash)) ///
    ci1opts(lcolor(navy)) ///
    ci2opts(lcolor(maroon)) ///
    xlabel(0 "No" 1 "Yes", labsize(medium)) ///
    ylabel(, format(%9.2f) labsize(medium) angle(horizontal)) ///
    title("") ///
    xtitle("Crisis in Current Year", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(label(1 "MDI = 0") label(2 "MDI = 0.5") label(3 "MDI = 1") rows(1) size(medium)) ///
    scheme(s1mono) ///
    xsize(7) ysize(5)

***************************************************************************************************************************************/

// Figure 8

// Model 1 (trust in military < 70%)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year if trust_military<.7, corr(ar1) link(probit) family(binomial) robust
estimates store A

// Model 2 (transformed dependent variable)
xtgee trust_military_mod trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust
estimates store B

// Model 3 (military dimension index = 0)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript l.military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year if military_dim==0, corr(ar1) link(probit) family(binomial) robust
estimates store C

// Plot
coefplot (A, msymbol(circle) mcolor(navy) ciopts(recast(rcap) lcolor(navy)) label("Trust in Military < 70%")) ///
         (B, msymbol(circle_hollow) mcolor(maroon) ciopts(recast(rcap) lcolor(maroon)) label("Transformed Dependent Variable")) ///
         (C, msymbol(diamond) mcolor(forest_green) ciopts(recast(rcap) lcolor(forest_green)) label("Military Dimension Index = 0")), ///
    keep(trust_police_z trust_judiciary_z gov_corrupt_z military_dim_z_mavg2 civwar conscript) ///
    order(trust_police_z trust_judiciary_z gov_corrupt_z military_dim_z_mavg2 civwar conscript) ///
    coeflabels(trust_police_z = "Trust Police" ///
              trust_judiciary_z = "Trust Judicial System" ///
              gov_corrupt_z = "Gov Corruption Perception" ///
              military_dim_z_mavg2 = "Military Dimension Index" ///
              military_dim_z_mavg2_l1 = "Military Dimension Index" ///
              civwar = "Civil War" ///
              conscript = "Conscription") ///
    xline(0, lcolor(gray) lpattern(solid)) ///
    xlabel(, labsize(small)) ///
    ylabel(, labsize(medium)) ///
    legend(pos(6) rows(2) size(small)) ///
    scheme(s1mono) ///
    ysize(4) xsize(7)
	
/***************************************************************************************************************************************

	2 - APPENDIX

***************************************************************************************************************************************/

// Table 2

sum trust_military trust_police trust_judiciary gov_corrupt gov_conf lead_approve living_std_improve military_dim conscript civwar military_rule military_leader conscript_time spend_soldier_ln personnel_pc_ln appointment_fa crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie crisis_time democracy_lib polity population_ln gdp_pc_ln gdp_growth life_expectancy hrights

***************************************************************************************************************************************/

// Table 3

xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust

***************************************************************************************************************************************/

// Table 4

// Model 1
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z jud_corrupt gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust
    
// Model 2
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z jud_high_ind jud_low_ind gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust
    
// Model 3
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z jud_corrupt jud_high_ind jud_low_ind gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust

***************************************************************************************************************************************/

// Table 5

/* For these regressions, download publicly available data from:
Feaver, P. D. (2023). Thanks for Your Service: The Causes and Consequences of Public Confidence in the US Military. Oxford University Press
Note: download data from Wave 1 */

// Rename variables
gen trust_military=.
replace trust_military=0 if Q8==4
replace trust_military=0 if Q8==3
replace trust_military=1 if Q8==2
replace trust_military=1 if Q8==1
gen other_trust=.
replace other_trust=0 if Q13==4
replace other_trust=0 if Q13==3
replace other_trust=1 if Q13==2
replace other_trust=1 if Q13==1

// Model 1
logit trust_military i.other_trust##i.party if DOV_ASSIGNMENT_A==1 & DOV_INSTITUTION==2 [pweight=weight]

// Model 2
logit trust_military i.other_trust##i.party if DOV_ASSIGNMENT_A==1 & DOV_INSTITUTION==1 [pweight=weight]

***************************************************************************************************************************************/

// Table 6

// Model 1 (Democracies and anocracies)
glm trust_military trust_military_l1 polity population_ln gdp_pc_ln trust_police_z trust_judiciary_z c.gov_corrupt##i.ideology_election i.year if polity > 0, link(probit) family(binomial) robust

// Model 2 (Democracies only)
glm trust_military trust_military_l1 polity population_ln gdp_pc_ln trust_police_z trust_judiciary_z c.gov_corrupt##i.ideology_election i.year if polity > 5, link(probit) family(binomial) robust

***************************************************************************************************************************************/

// Table 7

// For these regressions, download Gallup's World Poll respondent level data (2023)

// Rename variables
gen trust_military=.
replace trust_military=0 if WP137!=1 & WP137!=.
replace trust_military=1 if WP137==1 & WP137!=.
gen gov_corrupt=.
replace gov_corrupt=0 if WP146!=1 & WP146!=.
replace gov_corrupt=1 if WP146==1 & WP146!=.
gen trust_police=.
replace trust_police=0 if WP112!=1 & WP112!=.
replace trust_police=1 if WP112==1 & WP112!=.
gen trust_judiciary=.
replace trust_judiciary=0 if WP138!=1 & WP138!=.
replace trust_judiciary=1 if WP138==1 & WP138!=.

// Model 1 (Death Penalty)
probit trust_military trust_police trust_judiciary i.YEAR_CALENDAR i.gov_corrupt##i.WP3917 [pweight=wgt], vce(cluster WP5)

// Model 2 (Loyalty to Country)
probit trust_military trust_police trust_judiciary i.YEAR_CALENDAR i.gov_corrupt##i.WP3971_new [pweight=wgt], vce(cluster WP5)

// Model 3 (Migrant Acceptance Index)
probit trust_military trust_police trust_judiciary i.YEAR_CALENDAR i.gov_corrupt##c.INDEX_MAI [pweight=wgt], vce(cluster WP5)

// Model 4 (Climate Change)
probit trust_military trust_police trust_judiciary i.YEAR_CALENDAR i.gov_corrupt##i.WP4652 [pweight=wgt], vce(cluster WP5)

***************************************************************************************************************************************/

// Table 8

// Model 1
xtreg spend_soldier_ln l.spend_soldier_ln democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_military trust_police trust_judiciary gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie personnel_pc_ln i.year, robust

// Model 2
xtreg spend_soldier_ln l.spend_soldier_ln democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_military trust_police trust_judiciary gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie personnel_pc_ln i.year, fe robust

***************************************************************************************************************************************/

// Table 9

// Model 1 (trust in military < 70%)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year if trust_military < .7, corr(ar1) link(probit) family(binomial) robust

// Model 2 (transformed dependent variable)
xtgee trust_military_mod trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust

// Model 3 (military dimension index = 0)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript l.military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year if military_dim == 0, corr(ar1) link(probit) family(binomial) robust

***************************************************************************************************************************************/

// Figure 1

// First plot (democracies and anocracies)
glm trust_military trust_military_l1 polity population_ln gdp_pc_ln trust_police_z trust_judiciary_z c.gov_corrupt##i.ideology_election i.year if polity > 0, link(probit) family(binomial) robust
sum gov_corrupt if e(sample), d
margins, at(gov_corrupt=(0.44 0.86) ideology_election=(1(1)3)) ///
    atmeans vsquish ///
    post
marginsplot, name(all_democracies, replace) ///
    plot1opts(connect(line) msymbol(circle) lcolor(navy) mcolor(navy) lpattern(solid)) ///
    plot2opts(connect(line) msymbol(circle_hollow) lcolor(maroon) mcolor(maroon) lpattern(dash)) ///
    plot3opts(connect(line) msymbol(diamond) lcolor(forest_green) mcolor(forest_green) lpattern(shortdash)) ///
    ci1opts(lcolor(navy)) ///
    ci2opts(lcolor(maroon)) ///
    ci3opts(lcolor(forest_green)) ///
    xlabel(.44 "10th" .86 "90th", labsize(medium)) ///
    ylabel(, format(%9.2f) labsize(medium) angle(horizontal)) ///
    title("(a) Democracies and Anocracies", size(large)) ///
    xtitle("Government Corruption Perception (Percentiles)", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(label(1 "Left") label(2 "Center") label(3 "Right") rows(1) size(medium)) ///
    scheme(s1mono)

// Second plot (democracies only)
glm trust_military trust_military_l1 polity population_ln gdp_pc_ln trust_police_z trust_judiciary_z c.gov_corrupt##i.ideology_election i.year if polity > 5, link(probit) family(binomial) robust
sum gov_corrupt if e(sample), d
margins, at(gov_corrupt=(0.33 0.86) ideology_election=(1(1)3)) ///
    atmeans vsquish ///
    post
marginsplot, name(established_democracies, replace) ///
    plot1opts(connect(line) msymbol(circle) lcolor(navy) mcolor(navy) lpattern(solid)) ///
    plot2opts(connect(line) msymbol(circle_hollow) lcolor(maroon) mcolor(maroon) lpattern(dash)) ///
    plot3opts(connect(line) msymbol(diamond) lcolor(forest_green) mcolor(forest_green) lpattern(shortdash)) ///
    ci1opts(lcolor(navy)) ///
    ci2opts(lcolor(maroon)) ///
    ci3opts(lcolor(forest_green)) ///
    xlabel(.33 "10th" .86 "90th", labsize(medium)) ///
    ylabel(, format(%9.2f) labsize(medium) angle(horizontal)) ///
    title("(b) Democracies", size(large)) ///
    xtitle("Government Corruption Perception (Percentiles)", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(label(1 "Left") label(2 "Center") label(3 "Right") rows(1) size(medium)) ///
    scheme(s1mono)

// Combine graphs
graph combine all_democracies established_democracies, ///
    rows(1) ///
    ycommon ///
    scheme(s1color) ///
    xsize(12) ysize(7)
    
***************************************************************************************************************************************/

// Figure 2

// For these tests, download Gallup Worls Poll's respondent level data (2023)

// Rename variables
gen trust_military=.
replace trust_military=0 if WP137!=1 & WP137!=.
replace trust_military=1 if WP137==1 & WP137!=.
gen gov_corrupt=.
replace gov_corrupt=0 if WP146!=1 & WP146!=.
replace gov_corrupt=1 if WP146==1 & WP146!=.
gen trust_police=.
replace trust_police=0 if WP112!=1 & WP112!=.
replace trust_police=1 if WP112==1 & WP112!=.
gen trust_judiciary=.
replace trust_judiciary=0 if WP138!=1 & WP138!=.
replace trust_judiciary=1 if WP138==1 & WP138!=.

// Death penalty support interaction plot
probit trust_military trust_police trust_judiciary i.YEAR_CALENDAR i.gov_corrupt##i.WP3917 [pweight=wgt], vce(cluster WP5)
margins, dydx(gov_corrupt) at (WP3917=(1(1)2)) ///
	atmeans vsquish ///
    post
marginsplot, ///
    plot1opts(connect(line) msymbol(circle) lcolor(navy) mcolor(navy) lpattern(solid)) ///
    plot2opts(connect(line) msymbol(circle_hollow) lcolor(maroon) mcolor(maroon) lpattern(dash)) ///
    ci1opts(lcolor(navy*0.5) recast(rarea) color(navy%30)) ///
    ci2opts(lcolor(maroon*0.5) recast(rarea) color(maroon%30)) ///
    xlabel(, labsize(medium)) ///
    ylabel(, angle(0) format(%9.2f) labsize(medium)) ///
    title("Predicted Trust in the Armed Forces", size(large)) ///
    xtitle("Government Corruption", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(label(1 "Support Death Penalty") ///
           label(2 "Oppose Death Penalty") ///
           position(6) cols(2) size(medium) region(lcolor(white))) ///
    scheme(s1mono) ///
    xsize(7) ysize(5)
	
***************************************************************************************************************************************/

// Figure 3

xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z living_std_improve conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust
sum living_std_improve if e(sample), d
margins, at(living_std_improve=(.21 .61)) ///
	atmeans vsquish ///
    post
marginsplot, ///
    xlabel(.21 "10th" .61 "90th", labsize(small)) ///
    ylabel(, angle(0) format(%9.2f) labsize(small)) ///
    title("", size(large)) ///
    xtitle("Living Standards Improvement Perception (Percentiles)", size(medsmall)) ///
    ytitle("", size(medium)) ///
    legend(off) ///
    scheme(s1mono) ///
    xsize(7) ysize(5)

***************************************************************************************************************************************/

// Figure 4

// First plot (confidence in national government)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_conf conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year if military_dim_mavg2 == 0, corr(ar1) link(probit) family(binomial) robust
sum gov_conf if e(sample), d
margins, at(gov_conf=(.2 .67)) ///
	atmeans vsquish ///
    post
marginsplot, ///
    name(gov_conf_plot, replace) ///
    xlabel(.2 "10th" .67 "90th", labsize(medium)) ///
    ylabel(, angle(0) format(%9.2f) labsize(medium)) ///
    title("(a) Government Confidence", size(large)) ///
    xtitle("Confidence in Government (Percentiles)", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(off) ///
    scheme(s1mono)

// Second plot (leader approval)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z lead_approve conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year if military_dim_mavg2 == 0, corr(ar1) link(probit) family(binomial) robust
sum lead_approve if e(sample), d
margins, at(lead_approve=(.21 .69)) ///
	atmeans vsquish ///
    post
marginsplot, ///
    name(lead_plot, replace) ///
    xlabel(.21 "10th" .69 "90th", labsize(medium)) ///
    ylabel(, angle(0) format(%9.2f) labsize(medium)) ///
    title("(b) Leader Approval", size(large)) ///
    xtitle("Leader Approval (Percentiles)", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(off) ///
    scheme(s1mono)

// Combine graphs
graph combine gov_conf_plot lead_plot, ///
    rows(1) ///
    ycommon ///
    xsize(12) ysize(7) ///
    scheme(s1mono)

***************************************************************************************************************************************/

// Figure 5

// First plot (military rule)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_rule civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust
margins, at(military_rule=(0 1)) ///
	atmeans vsquish ///
    post
marginsplot, ///
    name(military_rule_plot, replace) ///
    xlabel(0 "No" 1 "Yes", labsize(medium)) ///
    ylabel(, angle(0) format(%9.2f) labsize(medium)) ///
    title("(a) Military Rule", size(large)) ///
    xtitle("Military Rule", size(medium)) ///
    ytitle("", size(medium)) ///
	legend(off) ///
    scheme(s1mono)

// Second plot (military leader)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_leader civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust
margins, at(military_leader=(0 1)) ///
	atmeans vsquish ///
    post
marginsplot, ///
    name(military_leader_plot, replace) ///
    xlabel(0 "No" 1 "Yes", labsize(medium)) ///
    ylabel(, angle(0) format(%9.2f) labsize(medium)) ///
    title("(b) Military Leader", size(large)) ///
    xtitle("Military Leader", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(off) ///
    scheme(s1mono)

// Combine graphs
graph combine military_rule_plot military_leader_plot, ///
    rows(1) ///
    ycommon ///
    xsize(12) ysize(7) ///
    scheme(s1mono)

***************************************************************************************************************************************/

// Figure 6

xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_dim_z_mavg2 crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln personnel_pc_ln c.civwar##c.hrights i.year, corr(ar1) link(probit) family(binomial) robust
sum hrights if e(sample), d
margins, at(civwar=(1 5) hrights=(-1.3 2.7)) ///
	atmeans vsquish ///
    post
marginsplot, name(civ_war_hr, replace) ///
    plot1opts(connect(line) msymbol(circle) lcolor(navy) mcolor(navy) lpattern(solid)) ///
    plot2opts(connect(line) msymbol(circle_hollow) lcolor(maroon) mcolor(maroon) lpattern(dash)) ///
    ci1opts(lcolor(navy)) ///
    ci2opts(lcolor(maroon)) ///
    xlabel(1 "1" 5 "5", labsize(medium)) ///
    ylabel(, format(%9.2f) labsize(medium) angle(horizontal)) ///
    title("") ytitle("") ///
    scheme(s1mono) ///
	xsize(7) ysize(5)

***************************************************************************************************************************************/

// Figure 7

// First plot (current conscription)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust
margins, at(conscript=(0 1)) ///
	atmeans vsquish ///
    post
marginsplot, ///
    name(conscript_plot, replace) ///
    xlabel(0 "No" 1 "Yes", labsize(medium)) ///
    ylabel(, angle(0) format(%9.2f) labsize(medium)) ///
    title("(a) Current Conscription", size(large)) ///
    xtitle("Conscription", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(off) ///
    scheme(s1mono)

// Second plot (lagged conscription)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z l.conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust
margins, at(L.conscript=(0 1)) ///
	atmeans vsquish ///
    post
marginsplot, ///
    name(lag_plot, replace) ///
    xlabel(0 "No" 1 "Yes", labsize(medium)) ///
    ylabel(, angle(0) format(%9.2f) labsize(medium)) ///
    title("(b) Lagged Conscription", size(large)) ///
    xtitle("Conscription", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(off) ///
    scheme(s1mono)

// Third plot (time since conscription)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript_time military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust
margins, at(conscript_time=(1 50)) ///
	atmeans vsquish ///
    post
marginsplot, ///
    name(time_plot, replace) ///
    xlabel(0 "0" 50 "50", labsize(medium)) ///
    ylabel(, angle(0) format(%9.2f) labsize(medium)) ///
    title("(c) Time Since Conscription", size(large)) ///
    xtitle("Years", size(medium)) ///
    ytitle("", size(medium)) ///
    legend(off) ///
    scheme(s1mono)

// Combine graphs
graph combine conscript_plot lag_plot time_plot, ///
    rows(1) ///
    ycommon ///
    xsize(14) ysize(8) ///
    scheme(s1mono)

***************************************************************************************************************************************/

// Figure 8

// Model 1 (original model)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust
estimates store model1

// Model 2 (2-year dummy for crisis)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_window2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust
estimates store model2

// Model 3 (5-year dummy for crisis)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_window5 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust
estimates store model3

// Model 4 (time since crisis)
xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_time_z crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln i.year, corr(ar1) link(probit) family(binomial) robust
estimates store model4

// Plot
coefplot ///
    (model1, label("Base Model")) ///
    (model2, label("2-Year Crisis")) ///
    (model3, label("5-Year Crisis")) ///
    (model4, label("Z-Score Crisis")), ///
    keep(crisis_current crisis_lag1 crisis_lag2 crisis_window2 crisis_window5 crisis_time_z) ///
    order(crisis_current crisis_lag1 crisis_lag2 crisis_window2 crisis_window5 crisis_time_z) ///
    coeflabels(crisis_current = "Current Crisis" ///
               crisis_lag1 = "Crisis (t-1)" ///
               crisis_lag2 = "Crisis (t-2)" ///
               crisis_window2 = "Crisis, 2-Year dummy" ///
               crisis_window5 = "Crisis, 5-Year dummy" ///
               crisis_time_z = "Time since crisis (std)") ///
    xline(0, lcolor(gray) lpattern(solid)) ///
    msymbol(circle) mcolor(black) ciopts(recast(rcap) lcolor(black)) ///
    xlabel(, labsize(medium)) ///
    ylabel(, labsize(medium)) ///
    legend(off) ///
    scheme(s1mono) ///
    ysize(6) xsize(8)
	
***************************************************************************************************************************************/

// Figure 9

xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_dim_z_mavg2 civwar spend_soldier_z_ln_mavg2 personnel_pc_ln c.crisis_time##i.crisis_victory crisis_tie i.year if crisis_tie==0, corr(ar1) link(probit) family(binomial) robust
margins, at(crisis_victory=(0 1) crisis_time=(0 50)) ///
    atmeans vsquish ///
    post
marginsplot, name(vic_time_plot, replace) ///
    plot1opts(connect(line) msymbol(circle) lcolor(navy) mcolor(navy) lpattern(solid)) ///
    plot2opts(connect(line) msymbol(circle_hollow) lcolor(maroon) mcolor(maroon) lpattern(dash)) ///
    ci1opts(lcolor(navy)) ///
    ci2opts(lcolor(maroon)) ///
	xlabel(0 "No" 1 "Yes", labsize(medium)) ///
    ylabel(, format(%9.2f) labsize(medium) angle(horizontal)) ///
    title("") ///
    xtitle("Victory", size(medium)) ///
    ytitle("") ///
    scheme(s1mono) ///
	xsize(7) ysize(5)

***************************************************************************************************************************************/

// Figure 10

xtgee trust_military trust_military_l1 democracy_lib population_ln gdp_pc_ln gdp_growth life_expectancy trust_police_z trust_judiciary_z gov_corrupt_z conscript military_dim_z_mavg2 civwar crisis_current crisis_lag1 crisis_lag2 crisis_victory crisis_tie spend_soldier_z_ln_mavg2 personnel_pc_ln appointment_fa i.year, corr(ar1) link(probit) family(binomial) robust
sum appointment_fa if e(sample), d
margins, at(appointment_fa=(-1.067 1.667)) ///
	atmeans vsquish ///
    post
marginsplot, ///
    name(appointment_fa_plot, replace) ///
    xlabel(-1.067 "10th" 1.667 "90th", labsize(medium)) ///
    ylabel(, angle(0) format(%9.2f) labsize(medium)) ///
    title("",) ///
    ytitle("",) ///
    xtitle("Appointment decisions in the armed forces (Percentiles)", size(medium)) ///
    legend(off) ///
    scheme(s1mono)












